""""
创建一个学生类
类名：Student
属性：姓名，年龄，学校，成绩(字典)
{'yuwen':100, 'suxue':100, 'yinyu':100}
方法：求总分、求平均值
"""
class Student(object):
    # grade = {'yuwen': 100, 'suxue': 100, 'yinyu': 100}
    # name = "yan"
    # age = 20
    # school = "一中"
    def __init__(self, name, age, school, grade):
        self.name = name
        self.age = age
        self.school = school
        self.grade = grade

    def grade_sum(self):
        a = []
        for i in self.grade.values():
            a.append(i)
        print(f"总分为：{sum(a)}")

    def grade_average(self):
        a = []
        for i in self.grade.values():
            a.append(i)
        b = sum(a)
        print(f"平均分为：{b / len(a)}")


student1 = Student("yan", 20, "一中", {'yuwen': 100, 'suxue': 100, 'yinyu': 100})
student1.grade_sum()
student1.grade_average()


"""
已经有Bus317这个类 
• 实例化一个对象 • 使用对象的属性 • 使用对象的方法 
• 添加实例属性 小 案 例 • 修改实例属性 • 添加类属性 
• 修改类属性 • 删除属性
"""

class Bus317(object):
    line = 317
    prod = "citroen"

    def __init__(self, driver_name):
        self.driver_name = driver_name


    def run(self, flag):
        if flag == 0:
            print("车从 a 开往 b")
        else:
            print("车从 b 开往 a")
#实例化对象
bus01 = Bus317("yan")
#使用对象的属性
print(bus01.prod)
print(bus01.line)
#使用对象的方法
bus01.run(1)
#添加实例属性
bus01.shape = "Cuboid"
print(f"bus01.shape is {bus01.shape}")
#修改实例属性
bus01.line = 1
print(f"bus01.line is {bus01.line}")
#添加类属性
Bus317.shape = "Cuboid"
print(f"Bus317.shape is {Bus317.shape}")
#修改类属性
Bus317.prod = "audi"
print(f"Bus317.prod is {Bus317.prod}")
#删除属性
del Bus317.prod
print(bus01.prod)# 报错
print(Bus317.prod)# 报错
